<script setup>
import { ref, onMounted } from 'vue'
import { useUserStore } from '@/stores/modules/user.js'
import { ElMessage } from 'element-plus'
import { userUpdateService } from '@/api/user.js'
const userStore = useUserStore()
const form = ref({})
const formRef = ref()
onMounted(() => {
  form.value = { ...userStore.userInfo }
  // form.value.createTime = dateFormat(form.value.createTime)
  // form.value.updateTime = dateFormat(form.value.updateTime)
})
const onSubmit = async () => {
  await formRef.value.validate()
  let res = await userUpdateService(form.value)
  if (res.code === 1) {
    ElMessage.error(res.message)
    return
  }
  if (res.code === 0) {
    ElMessage.success('修改成功')
    userStore.setUserInfo(form.value)
  }
}
</script>

<template>
  <el-card style="max-width: 100%; min-height: 90%; margin: 20px" shadow="hover">
    <template #header>
      <div class="card-header">
        <strong>基本资料</strong>
      </div>
    </template>
    <el-form :model="form" ref="formRef" label-width="auto">
      <el-form-item label="用户编号">
        <el-input v-model="form.id" disabled />
      </el-form-item>
      <el-form-item label="用户名">
        <el-input v-model="form.username" disabled />
      </el-form-item>
      <el-form-item label="昵称">
        <el-input v-model="form.nickname" />
      </el-form-item>
      <el-form-item label="电子邮箱">
        <el-input v-model="form.email" />
      </el-form-item>
      <el-form-item label="创建时间">
        <el-input v-model="form.createTime" disabled />
      </el-form-item>
      <el-form-item label="更新时间">
        <el-input v-model="form.updateTime" disabled />
      </el-form-item>
    </el-form>
    <template #footer>
      <el-button type="primary" @click="onSubmit">保存</el-button>
    </template>
  </el-card>
</template>

<style scoped>
.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
</style>
